package com.webcamtracker.image;

import com.webcamtracker.image.color.rgb.RGBColor;


public class GrayScaleColor implements Color {
    private int grayScale;
    private static final int GRAYCOLORVARIANT = 128;

    public GrayScaleColor(int rgbColor) {
        grayScale = (RGBColor.getBlue(rgbColor) + RGBColor.getGreen(rgbColor) + RGBColor.getRead(rgbColor)) / 3 / GRAYCOLORVARIANT;
    }

    public GrayScaleColor(RGBColor rgbColor) {
        grayScale = (rgbColor.getBlue() + rgbColor.getGreen() + rgbColor.getRed()) / 3 / GRAYCOLORVARIANT;
    }


    public int getGrayScale() {
        return grayScale;
    }

    public boolean isSimilar(Color color, double treshold) {
        int scale = ((GrayScaleColor) color).getGrayScale();
        return Math.abs(getGrayScale() - scale) < treshold;
    }

    public double[] elements() {
        return new double[]{getGrayScale()};
    }

}
